package com.chris.homecare.screens
{
	import com.chris.homecare.components.BreadcrumbComponenet;
	import com.chris.homecare.components.BulletHeadingComp;
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.components.renderers.ReviewListRenderer;
	import com.chris.homecare.data.FetchRemoteData;
	import com.chris.homecare.data.ReviewData;
	import com.chris.homecare.utils.CommonUtils;
	import com.chris.homecare.utils.ScreenNames;
	
	import feathers.controls.List;
	import feathers.controls.Screen;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.layout.VerticalLayout;
	
	import starling.display.Quad;
	import starling.events.Event;
	
	[Event(name="reviewData",type="starling.events.Event")]
	public class ReviewListScreen extends Screen
	{
		private var header:HeaderComponent;
		private var breadcrumbComp:BreadcrumbComponenet;
		private var reviewList:List;
		
		public static const REVIEW_DATA:String = "reviewData";
		
		public function ReviewListScreen()
		{
			super();
		}
		
		override protected function initialize():void
		{
			CommonUtils.previousScreen = ScreenNames.REVIEW_SCREEN;
			
			this.layout = new VerticalLayout();
			
			header = new HeaderComponent();
			header.addEventListener(Event.COMPLETE, onMenuBtnTrigger);
			addChild(header);
			
			breadcrumbComp = new BreadcrumbComponenet("Info", "Team","Ratings & Review");
			addChild(breadcrumbComp);
			
			
			var bulletHeadingComp:BulletHeadingComp = new BulletHeadingComp(CommonUtils.reviewHeading);
			addChild(bulletHeadingComp);
			
			reviewList = new List();
			
			reviewList.dataProvider = FetchRemoteData.currentRatingListCollection;
			reviewList.addEventListener(Event.CHANGE, onReviewListChange);
			reviewList.itemRendererFactory = function():IListItemRenderer
			{
				var renderer:ReviewListRenderer = new ReviewListRenderer();
				return renderer;
			};
			addChild(reviewList);
			reviewList.backgroundSkin = new Quad(10,10,0xFFFFFF);
			reviewList.backgroundDisabledSkin = new Quad(10,10,0xFFFFFF);
			
			super.initialize();
		}
		
		override protected function draw():void
		{
			var stageWidth:int = stage.stageWidth;
			var stageHeight:int = stage.stageHeight;
			
			reviewList.width = stageWidth;
			reviewList.height = stageHeight - reviewList.y;
			super.draw();
		}
		
		private function onMenuBtnTrigger(event:Event):void
		{
			this.dispatchEventWith(Event.COMPLETE);
		}
		
		private function onReviewListChange(event:Event):void
		{
			this.dispatchEventWith(REVIEW_DATA, false, ReviewData(reviewList.selectedItem));
		}
	}
}